package _21_多线程._1114_按序打印;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.SynchronousQueue;

public class _1114_按序打印_SynchronousQueue {

    private final BlockingQueue<Integer> second = new SynchronousQueue<>();

    private final BlockingQueue<Integer> three = new SynchronousQueue<>();

    public _1114_按序打印_SynchronousQueue() {
    }

    public void first(Runnable printFirst) throws InterruptedException {
        printFirst.run();
        second.put(1);
    }

    public void second(Runnable printSecond) throws InterruptedException {
        // 阻塞获取数据
        second.take();
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        three.put(1);
    }

    public void third(Runnable printThird) throws InterruptedException {
        three.take();
        // printSecond.run() outputs "second". Do not change or remove this line.
        printThird.run();
    }

}
